package com.tgb.util;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

/**
 * Created by hp on 2018/1/6.
 */
public class SqlSessionFactoryUtil {

    private static SqlSessionFactory singleton = null;
    private SqlSessionFactoryUtil() {

    }

    public static SqlSessionFactory getSqlSessionFactory() throws IOException {
        if(singleton == null) {
            String resource = "config/mybatis-config.xml";
            InputStream inputStream = Resources.getResourceAsStream(resource);
            singleton = new SqlSessionFactoryBuilder().build(inputStream);
        }
        return singleton;
    }
}
